home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
EnigmA Amiga Run 1996 March
/
EnigmA AMIGA RUN 05 (1996)(G.R. Edizioni)(IT)[!][issue 1996-03][Skylink CD IV].iso
/
earcd
/
program
/
lsthndln.lha
/
listhandling.doc
next >
Wrap
Text File
|
1995-11-09
|
5KB
|
192 lines
listhandling.m module v1.0 - by Eric Sauvageau.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Released to the Public Domain on November 10th, 1995.
This is a small Amiga E module I originally created for my own projects.
These functions are meant to ease the use and handling of Exec's linked
lists, such as those used in ListView gadgets.
The module should work with any Kickstart version, although it only has
been tested under 2.04 and up. It requires at least EC 3.0a to be used.
Exceptions:
~~~~~~~~~~~
Functions failing because of low memory will raise the exception "MEM".
Functions:
~~~~~~~~~~
list := lh_newList()
--------------------
DESCRIPTION:
Will initialize a standard Exec linked list.
INPUTS:
None.
RETURN:
A pointer to the new list.
EXAMPLE:
driveList := lh_newList()
node := lh_newnode(name,size)
-----------------------------
DESCRIPTION:
Create a new Exec listnode.
INPUTS:
"name" is a STRING holding the name of the new node.
"size" is the size of the node. For standard Exec listnodes, use
"SIZEOF ln".
RETURN:
A pointer to the new node, of "ln" type.
EXAMPLE:
node := lh_newnode('DF0:',(SIZEOF ln))
position := lh_addNodeSorted(list,node)
---------------------------------------
DESCRIPTION:
Add a listnode to a list. The nodes will be kept sorted by alphabetical
order (NON-case sensitive!). Duplicate nodes won't be added.
INPUTS:
"list" is the Exec list.
"node" is the listnode to be added.
RETURN:
The position in the list where the node has been added, or -1 if the node
wasn't added for some reason (already existing or error).
EXAMPLE:
position := lh_addNodeSorted(myList, someNode)
IF position = -1 THEN WriteF('Couldn''t add node \s!\n',someNode.name)
lh_freeList(list, deallocate=FALSE)
-----------------------------------
DESCRIPTION:
Will remove every nodes linked to a given list, and free the memory
associated with them. Can also deallocate the list itself if needed.
INPUTS:
"list" is the Exec list from which all nodes will be removed and freed.
"deallocate" is a boolean value. If "TRUE". the list structure itself
will be deallocated.
NOTES:
The nodes must be standard Exec ln structures! Or, at least, they
must not have anything else than LONG values. What I mean: the procedure
will free the memory allocated for node.name (which is a STRING ptr ), and
then the node structure itself. If some elements of your nodes are
PTR TO a memory area which needs specific de-allocation, this memory
will be lost (unless you're using an E memory allocation call, in which
case memory will be freed when the program is exited).
EXAMPLE:
lh_freeList(myList,TRUE)
position := lh_getPosition(list,name)
-------------------------------------
DESCRIPTION:
Returns the position in a list of the node named "name".
Usefull when you want to know what's the position of an item in a
ListView gadget, as example.
INPUTS:
"list" is an Exec list.
"name" is a STRING with the name of the node to be located.
RETURN:
The position of the "name" node in the list, or "-1" if the node couldn't
be found.
EXAMPLE:
IF (lh_getPosition(myList,'MONEY') THEN WriteF('Can''t find "MONEY"!\n')
node := lh_getNode(list,position)
---------------------------------
DESCRIPTION:
Returns a pointer to the "x"th node in the list.
INPUTS:
"list" is an Exec list.
"position" is the position of the desired node.
RETURNS:
A pointer to the node found at the specified position in the list.
EXAMPLE:
myNode := lh_getNode(myList, 3)
total := lh_itemsTotal(list)
----------------------------
DESCRIPTION:
Returns the number of nodes linked to the specified list.
INPUTS:
"list" is an Exec list.
RETURN:
The number of nodes linked to "list".
Additional informations
~~~~~~~~~~~~~~~~~~~~~~~
I make no guaranties that this module is bug-free or will work as
expected. I'm releasing it as a way to say "Thanks guys!" to the other
Amiga E programmers who released source code examples to the Public Domain,
which have often been VERY usefull to me.
Feel free to use this code in your own programs and to modify it if
something doesn't satisfy you. I just ask you to NOT release modified
versions of the module without at least asking me first. This way, we'll
avoid any mess if I decide to released an updated version at a later time
and someone already released his OWN update.
If you wish to reach me, you can Email me at:
Fidonet: Eric Sauvageau @ 1:242/907.0
Internet: dream@step.polymtl.ca (this account belongs to a friend. Try
the Fidonet address if there's no reply after a few days. As
soon the local Freenet will be up, I'll have my own address :)
I can also be found on #amiga on EffNet under the nick "RMerlin".